/*
 * Copyright (C) 2011 JiangHongTiao
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package sk.lieskove.jianghongtiao.aresapi.webservice.services;

import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import sk.lieskove.jianghongtiao.aresapi.enums.Jazyk;
import sk.lieskove.jianghongtiao.aresapi.enums.VersionEnum;
import sk.lieskove.jianghongtiao.aresapi.enums.Xml;
import sk.lieskove.jianghongtiao.multithreaddownloader.request.converter.*;
import sk.lieskove.jianghongtiao.multithreaddownloader.request.exceptions.ParameterNotAllowedException;

/**
 * <h3>Input</h3>
 *      <br />obligatory parameter:
 *      <code>ico</code>
 *      <p>parameters:
 *      <table class="TInvisible">
 *       <tr><td class="PAlignRight"><code>ico</code></td><td> - Reg.No. is an identification number under which the entity is registered
 *       in the Trade Register.
 *       The parameter is numerical, its maximum length is 8 digits. There is no need to enter the leading zeroes.
 *	 </td></tr>
 *
 *       <tr><td class="PAlignRight"><code>rozsah</code></td><td>
 *          <code>=0</code> - a basic data output (default value)<br />
 *          <code>=1</code> - the brief data output including cancelled trades<br />
 *          <code>=2</code> - the full data output including cancelled trades and permanent establishments</td></tr>
 *
 *       <tr><td class="PAlignRight"><code>xml</code></td><td>
 *          <code>=0</code> - xml (default value)<br />
 *          <code>=1</code> - html, transformation performed in browser on user's PC<br />
 *          <code>=2</code> - html, transformation from xml performed on server</td></tr>
 *
 *       <tr><td class="PAlignRight"><code>jazyk</code></td><td> - defines the text of html pages<br />
 *          <code>=cz</code> - html in Czech (default value)<br />
 *    		  <code>=en</code> - html in English</td></tr>
 *       <tr><td class="PAlignRight"><code>ver</code></td><td> - defines the xml output version (For details see <a href="ares_xml_get.html.en">Notes and recommendations</a>)<br />
 *
 *          <code>=1.0.5</code> - economy-sized xml with element names in abbreviations (default value)<br />
 *	  <code>=1.0.4</code> - version with full names of the elements</td><br />
 *       </tr>
 *       <tr><td class="PAlignRight"><code>stdadr</code></td><td> - defines the ouput of standardized address elements(<span class=
 *"XMLe">Adresa_UIR</span>)<br />
 *
 *          <code>=true</code> - data output including the standardized address<br />
 *          <code>=false</code> - data output without the standardized address (default value)<br />
 *<b>Note</b>:
 *The parameter is meaningful only in combination with the parameter <code>xml=0</code>.
 *Data of the standardization address are not transformed into html and usage the parameter extends uselessly the data output in this case.
 *When using this option, the data output containing more addresses (a lot of statutory representatives, the full output) can be longer in this case by reason of more size of returned data.
 *          </td></tr>
 *       </table>
 *
 *      <h3>Output</h3><br />
 *      <p>The TR service displays information selected from the Trade Register administered by the Ministry of Industry and Trade of the CR.</p>
 *
 *
 * Date of create: May 23, 2011
 *
 * @author JiangHongTiao <jjurco.sk_gmail.com>
 * @version 2011.0523
 */
public class TradeRegisterService extends EmptyService{
    
    
    private final Map<String, Converter> converters = new HashMap<String, Converter>();
    private Logger log = Logger.getLogger(this.getClass().getName());

    public TradeRegisterService() {
        log.debug("Creating "+this.getClass().getSimpleName()+" service!");
        String[] ver = new String[]{"1.0.4", "1.0.5"};
        converters.put("ico", new RegExpConverter(RegExpConverter.ICO_REGEPX));
        converters.put("xml", new EnumConverter(Xml.XML));
        converters.put("jazyk", new EnumConverter(Jazyk.EN));
        converters.put("ver", new StringEnumConverter(ver));
        converters.put("rozsah", new NumberEnumConverter("integer", new String[]{"0", "1", "2"}));
        converters.put("stdadr", new StringEnumConverter(new String[]{"true", "false"}));
        setConverters(converters);
        setObligatory(new String[]{"ico"});
        setOneOf(new String[]{});
        
        try {
            putParam("xml", "0");
        } catch (ParameterNotAllowedException ex) {
            log.error("Thrown unexpected exception. This never happened!" + ex);
        }
        
        setServiceUrl("http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_rzp.cgi");
        log.debug(this.getClass().getSimpleName()+" service created!");
    }
    
    public TradeRegisterService(VersionEnum version){
        this();
        try {
            putParam("ver", version.value());
        } catch (ParameterNotAllowedException ex) {
            log.error("Thrown unexpected exception. This never happened!" + ex);
        }
    }
    
}
